//
//  STCacheDataManager.m
//  赛拓
//
//  Created by 王磊 on 8/15/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STCacheDataManager.h"
#import <YYCache/YYCache.h>
@interface STCacheDataManager()

@property (nonatomic ,strong) YYCache *cache;

@end
static STCacheDataManager *instance = nil;
@implementation STCacheDataManager

+ (instancetype)getInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc]init];
    });
    return instance;
}

- (instancetype)init {
    if (self = [super init]) {
        self.cache = [YYCache cacheWithName:ST_Cache];
    }
    return self;
}

#pragma mark --- 首页缓存
- (void)saveHomeData:(id)data {
    
    [self.cache setObject:data forKey:ST_Home_Cache];
}

- (id)queryHomeData{
    
    return [self.cache objectForKey:ST_Home_Cache];
}
#pragma mark --- 用户帐号信息
- (void)saveAccountData:(id)data forKey:(NSString *)key {
    
    [self.cache setObject:data forKey:[NSString stringWithFormat:@"%@_%@",ST_Account_Cache,key]];
}

- (id)queryAccountDataForKey:(NSString *)key {
    return [self.cache objectForKey:[NSString stringWithFormat:@"%@_%@",ST_Account_Cache,key]];
}
#pragma mark --- 用户详细资料
- (void)saveSellerData:(id)data forKey:(NSString *)key {
    
    [self.cache setObject:data forKey:[NSString stringWithFormat:@"%@_%@",ST_Seller_Cache,key]];
}

- (id)querySellerDataForKey:(NSString *)key {
    
    return [self.cache objectForKey:[NSString stringWithFormat:@"%@_%@",ST_Seller_Cache,key]];
}
#pragma mark --- 用户使用协议
- (void)saveProtocolData:(id)data {
    
    [self.cache setObject:data forKey:ST_Protocol_Cache];
}

- (id)queryProtocolData {
    
    return [self.cache objectForKey:ST_Protocol_Cache];
}
#pragma mark --- 商家列表
- (void)saveSellerListData:(id)data {
    
    [self.cache setObject:data forKey:ST_Seller_List_Cache];
}

- (id)querySellerListData{
    
    return [self.cache objectForKey:ST_Seller_List_Cache];
}


#pragma mark --- 默认地区缓存 通过userid

- (void)saveDefaultAreasListData:(id)data {
    [self.cache setObject:data forKey:ST_Areas_List_Cache];
}

- (id)queryDefaultAreasListData {
    return [self.cache objectForKey:ST_Areas_List_Cache];
}
#pragma mark --- 商品
- (void)saveCommodityData:(id)data forKey:(NSString *)key {
    
    [self.cache setObject:data forKey:[NSString stringWithFormat:@"%@_%@",ST_Commodity_Cache,key]];
}

- (id)queryCommodityDataForKey:(NSString *)key {
    
    return [self.cache objectForKey:[NSString stringWithFormat:@"%@_%@",ST_Commodity_Cache,key]];
}

@end
